﻿
@{
    ViewBag.Title = "Hospital";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";

    var hos = ViewBag.Hospitals as List<LPY.LeHealth.Model.Hospital>;
}

@section Header{
<link href="~/Asset/font-awesome-4.6.3/css/font-awesome.min.css" rel="stylesheet" />
<script src="~/Asset/esimakin-twbs-pagination/jquery.twbsPagination.min.js"></script>
}

<div class="content">
    <div class="row">
        <div class="col-md-2">
            <div class="list-group">
                <a href="@Url.Action("Hospital", "Admin")" class="list-group-item active">医院管理</a>
                <a href="@Url.Action("GetHospitalAdmin", "Admin")" class="list-group-item ">医院管理员管理</a>
                @*<a href="@Url.Action("GetQueAdmin", "Admin")" class="list-group-item">问答管理员管理</a>*@                
            </div>
        </div>

        <div class="col-md-10">
            <div class="page-header clearfix" style="padding:10px;">
                <h4 class="pull-left">医院列表</h4>
                <!--操作按钮-->
                <div class="pull-right">
                    <a class="btn btn-success btn-sm" data-toggle="modal" data-target="#modal_add_hospital">添加医院</a>
                </div>
            </div>

            <!--内容区域-->
            @*<form id="user-search-form" class="form-inline well well-sm" action="/Exam/QueryExam" method="post" novalidate="">
                <div class="form-group">
                    <input type="text" id="keyword" name="ExamName" class="form-control" value="" placeholder="添加相关词">
                </div>
                <button class="btn btn-primary" type="submit">搜索</button>
            </form>*@

            <table id="user-table" class="table table-striped table-hover" data-search-form="#user-search-form">
                <thead>
                    <tr>
                        <td>机构名称</td>
                        <td>区域</td>
                        <td>等级</td>
                        <td>地址</td>
                        <td>预约通知</td>
                        @*<td>产品</td>*@
                        <td>操作</td>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in hos)
                    {
                        <tr>
                            <td>@item.Name</td>
                            <td>@item.AreaName</td>
                            <td>@item.GradeName</td>
                            <td>@item.Address</td>
                            <td>@string.Format("提前{0}天预约",item.AppointmentDay)</td>
                            @*<td><a href="/Admin/HospitalExamination/@item.Id">查看</a></td>*@
                            <td style="width:10%;">
                                <div class="btn-group">

                                    <a href="#" class="btn btn-default btn-sm">管理</a>
                                    <a href="#" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                        <span class="caret"></span>
                                    </a>

                                    <ul class="dropdown-menu">
                                        <li><a class="hospital_edit"  href="#" data-id="@item.Id">编辑</a></li>
                                        <li><a href="#" onclick="DelHospital(this,@item.Id)">删除</a></li>
                                        @*<li><a href="/Hospital/HospitalRegin?id=@item.Id">添加管理用户</a></li>*@
                                    </ul>
                                </div>
                            </td>
                        </tr>
                    }

                </tbody>
            </table>

            <!--分页-->
            <nav class=" text-center">
                <ul id="pagination" class="pagination-sm"></ul>
            </nav>
        </div>
    </div>
</div>

<div class="modal fade" id="modal_add_hospital" tabindex="-1" role="dialog" aria-labelledby="label_course">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="label_course"><strong>添加医院</strong></h4>
            </div>
            <div class="modal-body">
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Name" class="pull-right">名称</label>
                    </div>
                    <div class="col-md-7 controls">
                        <input id="Name" class="form-control" type="text">
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="AreaId" class="pull-right">所属区域</label>
                    </div>
                    <div class="col-md-7 controls">
                        <select id="AreaId" class="form-control">
                            <option value="1">裕华区</option>
                            <option value="2">长安区</option>
                            <option value="3">桥东区</option>
                            <option value="4">桥西区</option>
                            <option value="5">新华区</option>
                            <option value="6">开发区</option>
                        </select>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Address" class="pull-right">医院地址</label>
                    </div>
                    <div class="col-md-7 controls">
                        <input id="Address" class="form-control" type="text">
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Grade" class="pull-right">医院等级</label>
                    </div>
                    <div class="col-md-7 controls">
                        <select id="Grade" class="form-control">
                            <option value="1">公立三甲</option>
                            <option value="2">公立二甲</option>
                            <option value="3">公立一甲</option>
                            <option value="4">私立三甲</option>
                            <option value="5">私立二甲</option>
                            <option value="6">私立一甲</option>
                        </select>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="ExamTime" class="pull-right">上班时间</label>
                    </div>
                    <div class="col-md-7 controls">
                        <input id="ExamTime" class="form-control" type="text"><span>如：周一至周五7：30-11：30</span>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="AppointmentDay" class="pull-right">提前预约天数</label>
                    </div>
                    <div class="col-md-7 controls">
                        <select id="AppointmentDay" class="form-control">
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                        </select>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Detail" class="pull-right">医院描述</label>
                    </div>
                    <div class="col-md-7 controls">
                        <textarea id="Detail" class="form-control" style="height:180px;"></textarea>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <div id="doing" style="float:left;display:none;">
                    <i class="fa fa-circle-o-notch fa-spin"></i><span> 处理中...</span>
                </div>
                <div id="success" style="float: left; display: none; ">
                    <i class="fa fa-check-square"></i><span> 保存成功！</span>
                </div>
                <div id="error" style="float: left; display: none; ">
                    <i class="fa fa-warning"></i><span> 保存失败！</span>
                </div>

                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="btn_add_hospital" type="button" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="modal_edit_hospital" tabindex="-1" role="dialog" aria-labelledby="label_course">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="label_course"><strong>信息编辑</strong></h4>
            </div>
            <div class="modal-body">
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Name" class="pull-right">名称</label>
                    </div>
                    <div class="col-md-7 controls">
                        <input id="Name" class="form-control" type="text">
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="AreaId" class="pull-right">所属区域</label>
                    </div>
                    <div class="col-md-7 controls">
                        <select id="AreaId" class="form-control">
                            <option value="1">裕华区</option>
                            <option value="2">长安区</option>
                            <option value="3">桥东区</option>
                            <option value="4">桥西区</option>
                            <option value="5">新华区</option>
                            <option value="6">开发区</option>
                        </select>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Address" class="pull-right">医院地址</label>
                    </div>
                    <div class="col-md-7 controls">
                        <input id="Address" class="form-control" type="text">
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Grade" class="pull-right">医院等级</label>
                    </div>
                    <div class="col-md-7 controls">
                        <select id="Grades" class="form-control">
                            <option value="1">公立三甲</option>
                            <option value="2">公立二甲</option>
                            <option value="3">公立一甲</option>
                            <option value="4">私立三甲</option>
                            <option value="5">私立二甲</option>
                            <option value="6">私立一甲</option>
                        </select>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="ExamTime" class="pull-right">上班时间</label>
                    </div>
                    <div class="col-md-7 controls">
                        <input id="ExamTime" class="form-control" type="text"><span>如：周一至周五7：30-11：30</span>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="AppointmentDay" class="pull-right">提前预约天数</label>
                    </div>
                    <div class="col-md-7 controls">
                        <select id="AppointmentDay" class="form-control">
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                        </select>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Detail" class="pull-right">医院描述</label>
                    </div>
                    <div class="col-md-7 controls">
                        <textarea id="Details" class="form-control" style="height:180px;"></textarea>
                    </div>
                </div>
            </div>
            <input type="hidden" id="curren_id" />
            <div class="modal-footer">
                <div id="doing" style="float:left;display:none;">
                    <i class="fa fa-circle-o-notch fa-spin"></i><span> 处理中...</span>
                </div>
                <div id="success" style="float: left; display: none; ">
                    <i class="fa fa-check-square"></i><span> 保存成功！</span>
                </div>
                <div id="error" style="float: left; display: none; ">
                    <i class="fa fa-warning"></i><span> 保存失败！</span>
                </div>

                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="btn_edit_hospital" type="button" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>
@*<div class="modal fade" id="modal_add_user" tabindex="-1" role="dialog" aria-labelledby="label_course">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="label_course"><strong>添加医院管理员</strong></h4>
            </div>
            <div class="modal-body">
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Name" class="pull-right">用户名</label><input type="hidden" value="" id="result" name="result" />
                    </div>
                    <input value="" />
                    <div class="col-md-7 controls">
                        <input id="Name" class="form-control" type="text">
                    </div>
                </div>
                <input type="hidden" />
                <div class="row form-group">
                    <div class="col-md-3 control-label">
                        <label for="Address" class="pull-right">密码</label>
                    </div>
                    <div class="col-md-7 controls">
                        <input id="Password" class="form-control" type="password">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <div id="doing" style="float:left;display:none;">
                    <i class="fa fa-circle-o-notch fa-spin"></i><span> 处理中...</span>
                </div>
                <div id="success" style="float: left; display: none; ">
                    <i class="fa fa-check-square"></i><span> 保存成功！</span>                                             
                </div>
                <div id="error" style="float: left; display: none; ">
                    <i class="fa fa-warning"></i><span> 保存失败！</span>
                </div>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="btn_add_hospital" type="button" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>*@
@section Footer{
<script type="text/javascript">
    $(function () {
        $(".hospital_edit").click(function () {
            var id = $(this).attr("data-id");
            $.ajax({
                url: '@Url.Action("GetHospital", "Admin")',
                data: { id: id },
                type: 'post',
                async:false,
                success: function (data) {
                    if (data.Code = 1) {
                        $("#curren_id").val(data.Data.Id);
                        $("#modal_edit_hospital #Name").val(data.Data.Name);
                        $("#modal_edit_hospital #AreaId").val(data.Data.AreaId);
                        $("#modal_edit_hospital #Address").val(data.Data.Address);
                        $("#modal_edit_hospital #Grades").val(data.Data.GradeId);
                        $("#modal_edit_hospital #ExamTime").val(data.Data.ExamTime);
                        $("#modal_edit_hospital #AppointmentDay").val(data.Data.AppointmentDay);
                        $("#modal_edit_hospital #Details").val(data.Data.Detail);

                        $("#modal_edit_hospital").modal('show');
                    }
                }
            });
        });
       
           //编辑
        $("#btn_edit_hospital").click(function () {
                var id = $("#curren_id").val();
                var Name = $("#modal_edit_hospital #Name").val();
                var AreaId = $("#modal_edit_hospital #AreaId").val();
                var Address = $("#modal_edit_hospital #Address").val();
                var Grade = $("#modal_edit_hospital #Grades").val();
                var ExamTime = $("#modal_edit_hospital #ExamTime").val();
                var AppointmentDay = $("#modal_edit_hospital #AppointmentDay").val();
                var Details = $("#modal_edit_hospital #Details").val();

                //var selected = [];
                //$('#ItemsEdit option:selected').each(function () {
                //    selected.push($(this).val());
                //});

                $.ajax({
                    url: '@Url.Action("EditHostpital", "Admin")',
                    type: "post",
                    data: { id: id, Name: Name, AreaId: AreaId, Address: Address, Grade: Grade, ExamTime: ExamTime, AppointmentDay: AppointmentDay, Details: Details },
                    success: function (data) {
                        if (data.Code = 1) {
                            $("#doing").hide();
                            $("#success").show();
                            setTimeout(function () {
                                //$("#modal_add_course").modal('hide');
                                window.location.href = '@Url.Action("Hospital", "Admin")';
                            }, 1000);
                        }
                        else {
                            $("#doing").hide();
                            $("#error").show();
                        }
                    },
                    beforeSend: function (xhr) {
                        $("#btn_add_course").attr({ "disabled": "disabled" });
                        $("#doing").show();
                    },
                    complete: function (xhr, status) {
                        $("#doing").hide();
                    }
                });
            });

        $('#pagination').twbsPagination({
            totalPages: '@ViewBag.TotalPage',
            visiblePages: 5,
            first: "首页",
            prev: "上一页",
            next: "下一页",
            last: "尾页",
            href: '/Admin/Hospital?pageIndex={{pageNumber}}',
            hrefVariable: '{{pageNumber}}'
        });

        $('#modal_add_hospital').on('hidden.bs.modal', function (e) {
            //$("#name").removeAttr("disabled");
            //$("#des").removeAttr("disabled");
            $("#btn_add_course").removeAttr("disabled");

            $("#doing").hide();
            $("#success").hide();
            $("#error").hide();
            $("#name").val("");
            $("#des").val("");
        });

        $("#btn_add_hospital").click(function () {
            var name = $("#Name").val();
            var grade = $("#Grade").val();
            var detail = $("#Detail").val();
            var address = $("#Address").val();
            var AreaId = $("#AreaId").val();
            var ExamTime = $("#ExamTime").val();
            var AppointmentDay = $("#AppointmentDay").val();

            $.ajax({
                url: "@Url.Action("AddHospital", "Admin")",
                type: "post",
                data: { name: name, grade: grade, detail: detail, address: address, areaid: AreaId, examtime: ExamTime, AppointmentDay: AppointmentDay },
                success: function (data) {
                    if (data.Code = 1) {
                        $("#doing").hide();
                        $("#success").show();
                        setTimeout(function () {
                            $("#modal_add_course").modal('hide');
                            window.location.href = '@Url.Action("Hospital", "Admin")';
                        }, 1000);

                    }
                    else {
                        $("#doing").hide();
                        $("#error").show();
                    }
                },
                beforeSend: function (xhr) {
                    //$("#name").attr({ "disabled": "disabled" });
                    //$("#des").attr({ "disabled": "disabled" });
                    $("#btn_add_course").attr({ "disabled": "disabled" });
                    $("#doing").show();
                },
                complete: function (xhr, status) {
                    $("#doing").hide();
                }
            });
        });
    });

    function DelHospital(obj, Id) {

        if (confirm('是否删除?')) {
            $.ajax({
                type: "post",
                url: "/Admin/DelDetails",
                data: { Id: Id },
                success: function (data) {

                    if (data > 0) {
                        alert('删除成功!');
                        //$(obj).parent.parent.Remove();
                        location.href = "/Admin/Hospital";
                    }
                    else {
                        alert('删除失败!');
                    }
                }
            })
        }

    }
</script>
}